<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script>
			var timer;
			function getTime(){
				var d=new Date();
				var str=d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
				document.getElementById("timer").innerHTML=str;
			}
			//错误,没有timer元素
			//getTime();
			function initTime(){
				getTime();
				//window.setTimeout("getTime()",1000);
				timer=window.setInterval("getTime()",1000);
			}
			function stopTime(){
				window.clearInterval(timer);
			}
		</script>
	</head>
	<body onload="initTime()">
		<div id="timer"></div>
		<input type="button" value="停止时间" onclick="stopTime()"/>
	</body>
</html>
